<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增角色')" />
	<th:block th:include="include :: ztree-css" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-role-add">
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">创建人：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="name" id="name">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">订单金额：</label>
				<div class="col-sm-8">
					<input class="form-control" type="double" name="price" id="price">
					<span class="help-block m-b-none"><i class="fa fa-info-circle"></i>如：100.0</span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">订单备注：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="bz" id="bz">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">订单编号：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="code" id="code">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">订单状态：</label>
				<div class="col-sm-8">
					<select name="zt" class="form-control m-b">
						<option value="已提交">已提交</option>
						<option value="已支付">已支付</option>
						<option value="已取消">已取消</option>
						<option value="已完成">已完成</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">创建时间：</label>
				<div class="col-sm-8">
					<input id="time" name="time" class="form-control" type="date">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">修改时间：</label>
				<div class="col-sm-8">
					<input id="uptime" name="uptime" class="form-control" type="date">
				</div>
			</div>
			<!--<div class="form-group">
				<label class="col-sm-3 control-label is-required">显示顺序：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="roleSort" id="roleSort" required>
				</div>
			</div>-->
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: ztree-js" />
	<script type="text/javascript">
	    $(function() {
			var url = ctx + "system/menu/roleMenuTreeData";
			var options = {
				id: "menuTrees",
		        url: url,
		        check: { enable: true },
		        expandLevel: 0
		    };
			$.tree.init(options);
		});
		
		$("#form-role-add").validate({
			rules:{
				onkeyup: false,
				roleName:{
					remote: {
		                url: ctx + "system/role/checkRoleNameUnique",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"roleName" : function() {
		                		return $.common.trim($("#roleName").val());
		                    }
		                },
		                dataFilter: function(data, type) {
		                	return $.validate.unique(data);
		                }
		            }
				},
				roleKey:{
					remote: {
		                url: ctx + "system/role/checkRoleKeyUnique",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"roleKey" : function() {
		                        return $.common.trim($("#roleKey").val());
		                    }
		                },
		                dataFilter: function(data, type) {
		                	return $.validate.unique(data);
		                }
		            }
				},
				roleSort:{
					digits:true
				},
			},
			messages: {
		        "roleName": {
		            remote: "角色名称已经存在"
		        },
		        "roleKey": {
		            remote: "角色权限已经存在"
		        }
		    },
		    focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	        	add();
	        }
	    }
	
		function add() {
			var name = $("input[name='name']").val();
			var price = $("input[name='price']").val();
			var bz = $("input[name='bz']").val();
			var code = $("input[name='code']").val();
			var zt = $("select[name='zt']").val();
			var time = $("input[name='time']").val();
			var uptime = $("input[name='uptime']").val();
			//var menuIds = $.tree.getCheckedNodes();
			$.ajax({
				cache : true,
				type : "POST",
				url : ctx + "system/order/add",
				data : {
					"name": name,
					"price": price,
					"bz": bz,
					"code": code,
					"zt": zt,
					"time": time,
					"uptime": uptime
				},
				async : false,
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
					$.operate.successCallback(data);
				}
			});
		}
	</script>
</body>
</html>
